<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const jsonp = ({ url, params, callbackName }) => {
            const getUrl = () => {
                let dataSrc = ""
                for (let key in params) {
                    dataSrc += `${key}=${params[key]}&`
                }
                dataSrc += `callback=${callbackName}`
                return `${url}?${dataSrc}`
            }
            return new Promise((resolve, reject) => {
                const scriptEle = document.createElement('script');
                scriptEle.src = getUrl()
                document.body.appendChild(scriptEle)
                // window.upload = () => {}
                window[callbackName] = data => {
                    resolve(data)
                    document.body.removeChild(scriptEle)
                }
            })
        }
        jsonp({
            url: 'http://localhost:3000/img',
            params: {
                name: "qiqi",
                age: "20"
            },
            callbackName: 'upload'
        }).then(res => {
            console.log(res);
        })
    </script>
</body>

</html>